package com.thinkmore.es.config;

import com.xpc.easyes.autoconfig.annotation.EsMapperScan;
import com.xpc.easyes.autoconfig.config.EsAutoConfiguration;
import com.xpc.easyes.autoconfig.factory.IndexStrategyFactory;
import com.xpc.easyes.autoconfig.register.MapperScannerRegister;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;

/**
 * es配置
 */
@Component
@Import(MapperScannerRegister.class)
@EsMapperScan("com.thinkmore.es.mapper")
public class EsConfig {

    public EsConfig() {
        System.out.println("----------EsConfig init---------");
        //System.setProperty(PropertyKeyConstants.PROCESS_INDEX_MODE, "manual");
        //GlobalConfigCache.getGlobalConfig().setProcessIndexMode(ProcessIndexStrategyEnum.MANUAL);
    }

    @Bean
    public EsAutoConfiguration esAutoConfiguration() {
        return new EsAutoConfiguration();
    }

    @Bean
    public RestHighLevelClient restHighLevelClient(EsAutoConfiguration esAutoConfiguration) {
        return esAutoConfiguration.restHighLevelClient();
    }

    @Bean
    public IndexStrategyFactory indexStrategyFactory() {
        return new IndexStrategyFactory();
    }
}
